﻿using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.PermissionCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.RolePermissionCommandHandler
{
    /// <summary>
    /// 角色权限中介者
    /// </summary>
    public class RolePermissionCommandHandler : IRequestHandler<RolePermissionCommand, Results<List<Permission>>>
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IPermissionService _permissionService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"> 中介者 </param>
        public RolePermissionCommandHandler( IPermissionService permissionService)
        {
            _permissionService = permissionService;
        }
        /// <summary>
        /// 处理角色权限命令
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<List<Permission>>> Handle(RolePermissionCommand request, CancellationToken cancellationToken)
        {
            var list = await _permissionService.GetRolePermission(request.RoleId);
            return Results<List<Permission>>.DataResult(list);
        }
    }
}
